import type { Status } from './common'
import type { SurveyDBData } from './db'
import type { OptionsProps, PicLink, TextProps } from './editProps'

export enum ComsTypeEnum {
  // 编辑组件
  titleEditor = 'title-editor',
  descEditor = 'desc-editor',
  positionEditor = 'position-editor',
  sizeEditor = 'size-editor',
  weightEditor = 'weight-editor',
  italicEditor = 'italic-editor',
  colorEditor = 'color-editor',
  textTypeEditor = 'text-type-editor',
  picOptionEditor = 'pic-option-editor',

  // 通用组件
  singleSelect = 'single-select',
  muSelect = 'mu-select',
  optionSelect = 'option-select',
  singlePicSelect = 'single-pic-select',
  muPicSelect = 'mu-pic-select',
  // 业务组件
  textNode = 'text-node',
  personInfoGender = 'person-info-gender',
  personInfoEdu = 'person-info-edu',
}
// 题目类型
export type SurveyComName =
  | ComsTypeEnum.singleSelect
  | ComsTypeEnum.muSelect
  | ComsTypeEnum.optionSelect
  | ComsTypeEnum.singlePicSelect
  | ComsTypeEnum.personInfoEdu
  | ComsTypeEnum.personInfoGender

// 题目类型数组
export const SurveyComNameArr = [
  ComsTypeEnum.singleSelect,
  ComsTypeEnum.muSelect,
  ComsTypeEnum.optionSelect,
  ComsTypeEnum.singlePicSelect,
  ComsTypeEnum.personInfoEdu,
  ComsTypeEnum.personInfoGender,
]

// 判断传入的值是否为题目类型
export function isSurveyComName(value: string): value is SurveyComName {
  return SurveyComNameArr.includes(value as SurveyComName)
}

// 业务组件类型（题目类型+非题目类型）
export type Material = SurveyComName | ComsTypeEnum.textNode

export interface Actions {
  // [key: string]: (...args: any[]) => void
  setTextStatus: (textProps: TextProps, text: string) => void
  addOption: (optionProps: OptionsProps) => void
  rmOption: (optionProps: OptionsProps, index: number) => number
  setCurrentStatus: (optionProps: OptionsProps, index: number) => void
  setPicLinkByIndex: (optionProps: OptionsProps, payload: PicLink) => void
  changeEditorIsShowStatus: (optionProps: OptionsProps, type: number) => void
}

export interface MaterialStore extends Actions {
  currentMaterialCom: Material
  coms: Record<Material, Status>
  setCurrentMaterialCom: (comName: Material) => void
}

export interface EditorStore extends Actions {
  currentComIndex: number
  surveyCount: number
  coms: Status[]
  setCurrentComIndex: (index: number) => void
  addCom: (coms: Status[], newCom: Status) => void
  setStore: (storeStatus: SurveyDBData) => void
  initStore: () => void
  rmCom: (index: number) => void
  resetComs: () => void
}
